import { Redirect, Route } from 'react-router';
import { getToken } from 'utils/token';

export default function AuthRouter({ path, component: Com, ...rest }) {
  return (
    <Route {...rest} path={path} render={(props) => {
      // console.log(props);
      // const token = localStorage.getItem('geek_pc')
      const token = getToken()
      if (token) {
        return <Com {...props} />
      }
      else {
        return <Redirect to={{ pathname: '/', state: { form: props.history.location.pathname } }} />
      }
    }}></Route>
  )
}
